<template>
  <div>
    <vue-ueditor-wrap  @ready="ready" editor-id="ueditorBridge" v-model="currentValue" style="line-height: 20px;" :config="editorConfigNew"></vue-ueditor-wrap>
  </div>
</template>

<script>
import VueUeditorWrap from 'vue-ueditor-wrap'

export default {
  neme: 'Ueditor',
  components: {
    VueUeditorWrap,
  },
  props: {
    /* 编辑器的内容 */
    value: {
      type: String,
      default: '',
    },
  },
  watch: {
    value: {
      handler(val) {
        if (val !== this.currentValue) {
          this.currentValue = val === null ? '' : val
        }
      },
      immediate: true,
    },
    currentValue(val) {
      this.$emit('input', val)
    },
  },
  data() {
    return {
      currentValue: '',
      editorConfigNew: {
        autoHeightEnabled: true, // 自动变高
        autoFloatEnabled: true,
        elementPathEnabled: false,
        initialContent: '请输入内容',
        autoClearinitialContent: true,
        initialFrameWidth: '100%', // 初始化宽
        initialFrameHeight: '30%', // 初始化高
        // BaseUrl: "/admin/",
        // 后台配置接口
        serverUrl: process.env.VUE_APP_BASE_API + '/config',
        // UEditor 资源文件的存放路径
        UEDITOR_HOME_URL: '/UEditor/', // 必须配置好路径!!!
        zIndex: 99999, //设置z轴顺序值，避免工具栏下拉组件被遮挡
      },
      ueditor:undefined
    }
  },
  methods: {
    ready (editorInstance) {
      // console.log(`编辑器实例${editorInstance.key}: `, editorInstance);
      // this.$emit('ready', editorInstance);
      this.ueditor = editorInstance;
    },
    getContentText(){
      if(this.ueditor){
        console.log(this.ueditor)
        return this.ueditor.getContentTxt();
      }
      return "";
    }
  }

}
</script>

<style lang="scss" scoped>
</style>
